package top.lilele.adminSystem.web;

import cn.dev33.satoken.stp.StpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.lilele.adminSystem.dto.DailyDto;
import top.lilele.adminSystem.dto.IdParams;
import top.lilele.adminSystem.dto.StatisticsDailyDto;
import top.lilele.adminSystem.entity.AdminDailyEntity;
import top.lilele.adminSystem.service.AdminDailyService;
import top.lilele.adminSystem.utils.BaseResponse;
import top.lilele.adminSystem.utils.ResponseCodeEnum;
import top.lilele.adminSystem.vo.StatisticsDailyVo;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author lilele
 */
@Api(tags = "日报管理")
@RequestMapping(value = "daily")
@RestController
public class AdminDailyController {

    @Resource
    AdminDailyService adminDailyService;

    @ApiOperation(value = "新增日报")
    @PostMapping(value = "add")
    public BaseResponse add(@RequestBody @Validated AdminDailyEntity adminDailyEntity) {
        adminDailyEntity.setCreatedId(StpUtil.getLoginIdAsString());
        adminDailyService.add(adminDailyEntity);
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }

    @ApiOperation(value = "查询日报列表")
    @PostMapping(value = "queryDailyList")
    public BaseResponse queryDailyList(@RequestBody DailyDto dailyDto) {
        Object list = adminDailyService.queryDailyList(dailyDto, true);
        return BaseResponse.info(ResponseCodeEnum.Success, list);
    }

    @ApiOperation(value = "删除日报")
    @PostMapping(value = "deleteDailyById")
    public BaseResponse deleteDailyById(@RequestBody @Validated IdParams idParams) {
        adminDailyService.deleteDailyById(idParams.getId());
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }

    @ApiOperation(value = "根据id查询日报详情")
    @PostMapping(value = "queryDailyById")
    public BaseResponse queryDailyById(@RequestBody @Validated IdParams idParams) {
        AdminDailyEntity info = adminDailyService.queryDailyById(idParams.getId());
        return BaseResponse.info(ResponseCodeEnum.Success, info);
    }

    @ApiOperation(value = "根据id更新日报信息")
    @PostMapping(value = "updateDailyById")
    public BaseResponse updateDailyById(@RequestBody @Validated AdminDailyEntity adminDailyEntity) {
        adminDailyEntity.setUpdatedId(StpUtil.getLoginIdAsString());
        adminDailyService.updateDailyById(adminDailyEntity);
        return BaseResponse.info(ResponseCodeEnum.Success, null);
    }

    @ApiOperation(value = "导出日志报表")
    @PostMapping(value = "export")
    public void export(@RequestBody DailyDto dailyDto, HttpServletResponse httpServletResponse) {
        adminDailyService.export(dailyDto, httpServletResponse);
    }

    @ApiOperation(value = "查询日报统计报表")
    @PostMapping(value = "queryStatisticsDailyList")
    public BaseResponse queryStatisticsDailyList(@RequestBody StatisticsDailyDto statisticsDailyDto) {
        List<StatisticsDailyVo> list = adminDailyService.queryStatisticsDailyList(statisticsDailyDto);
        return BaseResponse.info(ResponseCodeEnum.Success, list);
    }

    @ApiOperation(value = "导出日报统计报表")
    @PostMapping(value = "exportStatisticsDaily")
    public void exportStatisticsDaily(@RequestBody StatisticsDailyDto statisticsDailyDto, HttpServletResponse httpServletResponse) {
        adminDailyService.exportStatisticsDaily(statisticsDailyDto, httpServletResponse);
    }
}
